package com.proposition.commons.exam.util;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.proposition.commons.exam.exception.ExamAddException;
import com.proposition.commons.exam.result.Result;
import com.proposition.commons.exam.result.ResultEnum;
import com.proposition.commons.model.*;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 11:37 2017/11/6
 * @description:试题添加工具类
 */
public class ExamAddUtil {
    /**
     *@author: 陈玉林 
     *@date: 2017/11/7 15:03 
     *@description: 验证试题题干是否唯一
     */
    public static void volidateUniqueStem(Object obj) {
        Object selectResult = null;
        if (obj instanceof ExamAcupoint) {
            ExamAcupoint exam = (ExamAcupoint) obj;
            selectResult=exam.selectOne(new EntityWrapper<ExamAcupoint>()
                    .eq("stem", exam.getStem()).eq("category_id", exam.getCategoryId()));
        } else if (obj instanceof ExamAcupointAdult) {
            ExamAcupointAdult exam = (ExamAcupointAdult) obj;
            selectResult=exam.selectOne(new EntityWrapper<ExamAcupointAdult>()
               .eq("stem", exam.getStem()).eq("category_id", exam.getCategoryId()));
        }else if (obj instanceof  ExamAcupointPediatric) {
            ExamAcupointPediatric exam = (ExamAcupointPediatric) obj;
            selectResult=exam.selectOne(new EntityWrapper<ExamAcupointPediatric>()
               .eq("stem", exam.getStem()).eq("category_id", exam.getCategoryId()));
        } else if (obj instanceof ExamAnswer10) {
            ExamAnswer10 exam = (ExamAnswer10) obj;
            selectResult=exam.selectOne(new EntityWrapper<ExamAnswer10>()
                    .eq("stem", exam.getStem()).eq("category_id", exam.getCategoryId()));
        }else if (obj instanceof ExamAnswer30) {
            ExamAnswer30 exam = (ExamAnswer30) obj;
            selectResult=exam.selectOne(new EntityWrapper<ExamAnswer30>()
                    .eq("stem", exam.getStem()).eq("category_id", exam.getCategoryId()));
        }
        if (selectResult != null) {
            throw new ExamAddException(ResultEnum.ILLEGAL_STEM_EXIST);
        }
    }
}
